
<template>
  <el-form ref="form" :model="data" :rules="rules" status-icon label-width="100px">
    <el-form-item label="客户名称" prop="name">
        <el-input v-model.trim="data.name" placeholder="请填写客户名称" />
    </el-form-item>
    <el-form-item label="联系人" prop="contact_name">
        <el-input v-model.trim="data.contact_name" placeholder="请填写联系人" />
    </el-form-item>
    <el-form-item label="联系方式" prop="contact_phone">
        <el-input v-model.trim="data.contact_phone" placeholder="请填写联系方式" />
    </el-form-item>
    <el-form-item label="联系地址" prop="contact_address">
        <el-input v-model.trim="data.contact_address" placeholder="请填写联系地址" />
    </el-form-item>
    <el-form-item label="所属行业" prop="industry">
        <el-input v-model.trim="data.industry" placeholder="请填写所属行业" />
    </el-form-item>

    <el-dialog :visible.sync="dialogVisible" width="30%" append-to-body>
          <img width="100%" :src="previewUrl" alt="">
    </el-dialog>  
    <el-form-item>
      <el-button type="primary" icon="el-icon-check" :disabled="$store.state.settings.ajaxButton" @click="submit">提交</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import { create } from '@/api/customer'
import { getToken } from '@/utils/auth'


export default {
  name: 'customerCreate',
  components: { },
  props: {
    item: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      loading:false,
      dialogVisible:false,
      previewUrl:'',
      headerObj: {
            'Authorization': 'Bearer ' + getToken()
        },
      rules: {
        name: [
            { required: true, message: '请输入客户名称', trigger: 'blur' },
          ],
        contact_name: [
          { required: true, message: '请输入联系人名称', trigger: 'blur' },
        ],
        contact_name: [
          { required: true, message: '请输入联系人名称', trigger: 'blur' },
        ],
        contact_phone: [
          { required: true, message: '请输入联系方式', trigger: 'blur' },
        ],
        contact_address: [
          { required: true, message: '请输入联系地址', trigger: 'blur' },
        ],
      },
      data: {
             name:'',
            contact_name:'',
            contact_phone:'',
            contact_address:'',
            industry:'',

      }
    }
  },
  created() {
  },
  methods: {
    
    
    
    submit() {
 
      const thiz = this

      this.$refs.form.validate(valid => {
        if (!valid) {
          return false
        }
        create({
             name:this.data.name,
            contact_name:this.data.contact_name,
            contact_phone:this.data.contact_phone,
            contact_address:this.data.contact_address,
            industry:this.data.industry,

        }).then(response => {
          this.$store.commit('settings/SET_AJAX_BUTTON', true);
          this.$message({
            message: '添加成功',
            type: 'success',
            duration: 1500,
            onClose() {
              if (thiz.$refs.form !== undefined) {
                thiz.$refs.form.resetFields()
              }
              thiz.item.dialogVisible = false
            }
          })
        })
      })
    }
  }
}
</script>

